﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using PBOffice.BLL;
using System.Data;
using PBOffice.DAL;

public partial class MeetingManager_MeetingBook : System.Web.UI.Page
{
    MeetingManagerBLL meet = new MeetingManagerBLL();
    protected void Page_Load(object sender, EventArgs e)
    {
        GridAddDate();
    }
    /// <summary>
    /// 获取会议室预订信息的方法
    /// </summary>
    private void GridAddDate()
    {
        if (txtDate.Text == "")
        {
            DateTime t = DateTime.Now;
            GridView1.DataSource = meet.GetRoombook(t);
            GridView1.DataBind();
        }
        else
        {
            DateTime dt = Convert.ToDateTime(txtDate.Text);
            DataSet ds = meet.GetRoombook(dt);
            GridView1.DataSource = ds;
            GridView1.DataBind();
        }

        for (int i = 0; i < GridView1.Rows.Count; i++)
        {

            for (int j = 1; j < GridView1.Rows[i].Cells.Count; j++)
            {
                Button btn = new Button();
                btn.Attributes.Add("style","border-style:none; color:green;padding-lefe:30px;");

                if (GridView1.Rows[i].Cells[j].Text == "0")
                {
                    btn.Text = "空闲";
                   
                    btn.Enabled = true;
                }
                else if (GridView1.Rows[i].Cells[j].Text == "1")
                {
                    User user=(User)Session["userManage"];
                    btn.Text = user.UserId;
                    btn.Enabled = false;
                }


                GridView1.Rows[i].Cells[j].Controls.Add(btn);
                btn.Click += new EventHandler(btn_Click);
            }
        }
    }

    void btn_Click(object sender, EventArgs e)
    {
        Button a = sender as Button;
        User user=(User)Session["userManage"];
        a.Text =user.UserId;
        
        RoomBook rb = new RoomBook();
        if (txtDate.Text != "")
        {
            DateTime dt1 = Convert.ToDateTime(txtDate.Text);
            rb.BookDate = dt1;
        }
        else
        {
            rb.BookDate = DateTime.Now;
        }
        User user1 = new PBOffice.DAL.User();
        rb.User = user1;
        rb.User .UserNo = user.UserNo;
  
        int time = ((GridViewRow)a.NamingContainer).RowIndex;

        for(int i=0;i<GridView1.Columns.Count;i++)
        {
             int week =Convert.ToInt32(GridView1.Rows[time].Cells[i].Text);

        }
    }

    /// <summary>
    /// 
    /// 查询某一天的会议室预订情况
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnSearch_Click(object sender, EventArgs e)
    {
        GridAddDate();
    }
}